package com.csg.ses.common.db;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @auther wangjun
 * @time 2020/11/16 20:18
 * 动态数据源AOP切面类
 */
@Component
@Order(value = -100)
@Slf4j
@Aspect
public class DataSourceSwitchAspect {

    @Pointcut("execution(* com.csg.ses.dao.ses..*.*(..))")
    private void sesAspect() {
    }

    @Pointcut("execution(* com.csg.ses.dao.yxxt..*.*(..))")
    private void yxxtAspect() {
    }

    @Before("sesAspect()")
    public void ses_db() {
        DbContextHolder.setDbType(DBTypeEnum.ses);
    }

    @Before("yxxtAspect()")
    public void yxxt_db() {
        DbContextHolder.setDbType(DBTypeEnum.yxxt);
    }
}